from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--disable-gpu")
driver = webdriver.Chrome(executable_path="/opt/bin/chromedriver",
                          options=options)
driver.get(
    "https://movie.douban.com/explore#!type=movie&tag=%E7%83%AD%E9%97%A8&sort=recommend&page_limit=20&page_start=0")
try:
    # 等待期望的条件发生
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "list")))
except Exception as e:
    print(e)

time.sleep(5)
# 找到"加载更多标签"，并请求更多数据
search_tag = driver.find_element_by_name("search_text")
search_tag.send_keys("成龙")
search_tag.submit()
time.sleep(5)

# 获取用户信息
# tag = driver.find_element_by_class_name("list")
#
# assert isinstance(tag, WebElement)
# # for t in tag.find_elements_by_tag_name("tr"):
# #     user_info = t.find_elements_by_tag_name("td")
# #     username = user_info[0].text
# #     age = user_info[1].text
# #     gender = user_info[2].text
# for t in tag.find_elements_by_class_name('item'):
#     title = t.find_element_by_tag_name('p')
#     score = t.find_element_by_tag_name('strong')
#
#     print(title.text,score.text)

driver.quit()
